/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package etherblocks.mods.shooter.entitysystem.systems;

import com.jme3.math.Vector3f;
import etherblocks.game.entitysystem.*;
import etherblocks.game.entitysystem.components.*;
import etherblocks.mods.shooter.entitysystem.components.*;

/**
 *
 * @author Carl
 */
public class ZombieSpawnSystem implements EntitySystem{

    @Override
    public void onNextFrameCalculation(EntityMap entityMap, float lastTimePerFrame){
        for(Entity entity : entityMap.getEntities(ShootableComponent.class, RemovedComponent.class)){
            spawn(entityMap);
        }
    }
    
    public static void spawn(EntityMap entityMap){
        Entity entity = entityMap.createNewEntity();
        EntityTemplate.loadTemplate(entity, "zombie");
        Vector3f location = new Vector3f((float) Math.random(), 0, (float) Math.random()).multLocal(100).addLocal(0, 60, 0);
        entity.setComponent(new LocationComponent(location, System.currentTimeMillis()));
        entity.setComponent(new RotationComponent(new Vector3f(1, 0, 0), System.currentTimeMillis()));
        entity.setComponent(new AnimationComponent("walk", 1.5f));
        entity.setComponent(new RandomMoveDirectionComponent(0));
        entity.setComponent(new HealthComponent(1));
        entity.setComponent(new ShootableComponent());
    }
}
